package o2o.dao.PO.wallet;

import com.jinyou.utils.common.ValidateUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import o2o.cache.company.postman.PostCompanyMemory;
import o2o.cache.shop.ShopMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.dao.PO.common.UserType;
import o2o.dao.PO.company.postman.PostCompanyInfo;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.VO.shop.ShopInfoVO;
import o2o.dao.VO.user.UserInfoVO;
import o2o.dao.VO.wallet.UserWalletPopVO;
import org.springframework.beans.BeanUtils;
import o2o.system.data.SYS_CONFIG_PATH;

//工人提现记录
@Data
@Accessors(chain = true)
public class UserWalletPop {

    public static final Integer USER_POP_TYPE_BALANCE = 2; // 用户 余额提现

    public static final Integer USER_POP_STATUS_APPLYING = 0; // 用户 申请提现中
    public static final Integer USER_POP_STATUS_PASS = 1; // 用户提现  申请通过
    public static final Integer USER_POP_STATUS_DISPASS = 2; // 用户提现 申请被拒绝

    private Long id;//ID

    private Long shopId;//工人id

    private String username;//用户账号
    private Integer userType;//用户类型
    private Integer userPopType;    //  用户提现类型  例如 商家提现  配送员提现 代理提现
    private Long fromCompanyId; // 配送员申请提现公司

    private Double money;//本次提现金额
    private Double afterMoney;//操作后金额

    private Double fcMoney;//本次提现金额(外币)
    private Double exchangeRate;// 汇率

    private String channel;//渠道 微信wx，支付宝alipay
    private int isDone;//是否提现成功  1成功  0未成功
    private Integer popType;//提现类型  2余额提现 7押金提现 8扣除押金

    private Double actualTransferMoney; // 实际打款金额
    private Double actualFcTransferMoney; // 实际打款金额(外币)
    private Integer isAutoTransfer; // 是不是自动打款
    private String outTradeNo; //  微信或者支付宝打款订单号

    private String alipay;//店铺支付宝帐号
    private String alipayRealName;//店铺支付宝对应的真实姓名
    private String tenpay;//店铺微信帐号
    private String tenpayopenId;//店铺微信帐号openId
    private String tenpayRealName;//店铺微信帐号真实姓名

    private String bankUserName;//银行卡开户人姓名
    private String bankName;//银行卡开户行
    private String bankCard;//银行卡号

    private Long popTime;//确定提现时间

    private String createUser;// 创建者
    private long createTime;// 创建日期 141231212423423时间戳毫秒级标识
    private int delFlag;// 是否已删除(0未删除,1已删除)
    private String updateUser;// 最后更新着
    private String note;//备注
    private String voucherImageUrl; //  凭证图片地址
    private String extra1;//备用字段1
    private String extra2;//备用字段2
    private String extra3;//备用字段3
    private ShopInfoVO shopInfo;
    private UserInfoVO userInfo;

    public UserWalletPopVO convert2VO() {
        UserWalletPopVO vo = new UserWalletPopVO();
        BeanUtils.copyProperties(this, vo);
        if (this.fromCompanyId != null) {
            PostCompanyInfo companyInfo = PostCompanyMemory.getInstance().getById(this.fromCompanyId);
            if (companyInfo != null) {
//                vo.setPostCompanyInfo(companyInfo);
                vo.setFromCompanyName(companyInfo.getCompanyName());
            }
        }

        if (0 == UserType.SHOP_OWNER - this.getUserType()) {
            ShopInfo shopInfo = ShopMemory.getInstance().getShopById(this.getShopId());
            if (null != shopInfo) {
                vo.setShopInfo(shopInfo.convert2VO());
            }
        }

        if (ValidateUtil.isNotNull(vo.getUsername())) {
            UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(vo.getUsername());
            if (null != userInfo) {
                vo.setName(userInfo.getName());
                if (ValidateUtil.isNotNull(userInfo.getSignPhoto())) {
                    if (ValidateUtil.isNotNetUrl(userInfo.getSignPhoto())) {
                        vo.setUserImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + userInfo.getSignPhoto());
                    } else {
                        vo.setUserImageUrl(userInfo.getSignPhoto());
                    }
                }
                vo.setName(userInfo.getName());
                vo.setTelPhone(userInfo.getTelPhone());
            }
        }
        return vo;
    }

}
